/**
 * 登录模块，提供登录相关业务功能
 * 
 * @Date: 2015-6-16
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(["jquery", "datagridServ","sysmanMain", "bizProto","btnServ"],
		function($,datagridServ, sysmanMain, bizProto,btnServ) {

			'use strict';

			var _bizProto,_moduleConfig,_buttonConfig,
				//锚记datagrid目标元素
				$dg,
				//初始化后的datagrid dom对象
				$grid,
				//编辑弹窗对象及弹窗按钮对象
				$edit_window,$edit_window_height=700,$edit_window_width=900,window_btn,
				
				//业务表单对象
				$form				
				
			var public_method = {				
				
				init:function(doc){
					_moduleConfig = sysmanMain.getCurrentModuConfig();
					private_method.init(doc);
					
				}
				
			}

			var private_method = {
				init : function(doc) {
					if (window.console) {
					console.info('bug modules gets ready and been loaded.');
					}
					
					_bizProto = new bizProto({doc:doc,rootId:'panel-bug',panelSelector:'div.well',subSystemCode:'sysman',moduleCode:'bug'})
					_buttonConfig={
						"新增":private_method.add,
					    "编辑":private_method.edit,
						 "删除":private_method.del
						 								
					}
					
					private_method.initPath();
					private_method.initElement(_bizProto.pageDoc)
					
				},
				
				//初始化路径
				initPath:function(){
					
				},				
				
				//初始化元素
				initElement:function(doc){
					
					
					$dg = $(doc).find("#bug-dg");
					$grid = $dg.datagrid({
						height:_bizProto.pageHeight,
						url : _bizProto.flowQueryUrl,
						queryParams:{fullBizcode:_moduleConfig.fullBizcode},
						width : 'auto'						
					});

					// 编辑窗口初始化
					$edit_window = $('#bug-win')					
					
					
					
					
					//初始化操作按钮
					var listTd = $(_bizProto.pageDoc).find('#tb-bug td')
										
					var _param = {
						bizcode:_moduleConfig.fullBizcode,
						rootPath:_bizProto.rootPath,
						container:listTd,
						callback:private_method.bindBtnEvent}
					btnServ.generateListBtn(_param);

					$.messager.progress('close');
				},
				
				//绑定按钮事件
				bindBtnEvent:function(){
					// 绑定按钮事件
					var btn = $(_bizProto.pageDoc).find('#tb-bug a.function-btn')
					$(btn).unbind('click');
					$(btn).bind('click', private_method.function_btn_listenner)			
					
					
				},
				
				setComboValue:function(node,target){
		    		if(node!=null){		    			
		    			$(target).val(node.text);
		    		}
		    	},
				// 功能按钮监听函数
				function_btn_listenner : function(e) {

					btnServ.applyButton({buttonEvt:e,buttonConfig:_buttonConfig})

				},
				// 新增函数
				add : function() {
					$($grid).datagrid('clearSelections')
					private_method.edit(false);
				},
				// 编辑,flag 为form按钮可见性标志
				edit : function(flag) {					
					var _param = {grid:$grid,window:$edit_window,href:_bizProto.flowEidtPageUrl,width:$edit_window_width,height:$edit_window_height,flag:flag,existCheckElement:'form'}
					datagridServ.windowEdit(_param);					
				},
				
				
				// 删除
				del : function() {
					if (window.console) {
					console.info('bug delete on air ...');
					}
					datagridServ.delRow({url:_bizProto.delUrl,target:$grid});
				}

			};

			
			return public_method;

		});